package basic.courseLearn01;


import basic.courseLearn01.utils.FunctionSort;
import basic.courseLearn01.utils.SortUtils;
import org.junit.Test;

//选择排序（从小到大）
public class SelectSorting implements FunctionSort {

    //代码思路：每次选择最小的放到合适位置
    public int[] selectSort(int [] result){
        int index=0;
        for (int i = 0; i < result.length; i++) {       //0-i，已经排序成功
            index=i;
            for (int j = i; j < result.length; j++) {       //取最小的数的下标
                if (result[index]>result[j]){
                    index=j;
                }
            }
            SortUtils.swap(result,i,index);
        }
        return result;
    }

    @Override
    public int[] sort(int[] result) {
        return selectSort(result);
    }


    @Test
    public void testSelectSort(){
        SortUtils.executeCheckAlgorithm(1_0000,1000,1000,this);
    }



}
